public class Case1 {
    public static void main(String[] args) {
        // aabccccaaa
        // a2bc4a3
        if (args.length != 1)
        {
            System.out.println("please use a string parameter ,such as aabccccaaa");
            System.exit(-1);
        }
        String str = args[0];
        String compress = string2Compress(str);
        System.out.println(compress);

    }

    private static String string2Compress(String str)
    {
        int count = str.length();
        char first = str.charAt(0);
        int sameCharCount = 1;
        String compressStr = null;
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 1;i< count;i++)
        {
            char next = str.charAt(i);
            if (first==next)
            {
                sameCharCount++;
                continue;
            }
            stringBuilder.append(first).append(sameCharCount);
            first = next;
            sameCharCount = 1;
        }
        stringBuilder.append(first).append(sameCharCount);
        compressStr = stringBuilder.toString();

        return compressStr;
    }
}
